//
//  DDHomeManager.m
//  Dingdong
//
//  Created by 程强 on 16/12/8.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDHomeManager.h"
#import "DDCarouselSet.h"
#import "DDBotPitObj.h"
#import "DDHotSaleSet.h"
#import "DDTopHotGoodsSet.h"
#import "DDHomeAdsSet.h"
#import "DDHomeCategorySet.h"
#import "DDHotSearchSet.h"

@implementation DDHomeManager
- (DSASubject *)getHomeTopCarousel
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/carousel.do", ServerUrl];
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDCarouselSet *set = [DDCarouselSet modelWithDictionary:dic];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)getHomeCategory
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/category.do", ServerUrl];
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDHomeCategorySet *set = [DDHomeCategorySet modelWithDictionary:dic];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)getHomeHorizontalGoodsWithBanner
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/goodsPit.do", ServerUrl];
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDBotPitObj *set = [DDBotPitObj modelWithDictionary:dic[@"data"]];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)getHomeVerticalGoodsListWithPageNo:(NSInteger)pageNo size:(NSInteger)size
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/bottomGoodsPit.do", ServerUrl];
    NSDictionary *dic = @{@"pageNo":@(pageNo),@"pageSize":@(size)};
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDHotSaleSet *set = [DDHotSaleSet modelWithDictionary:dic[@"data"]];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)getTopHotGoodsList
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/topGoodsPit.do", ServerUrl];
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDTopHotGoodsSet *set = [DDTopHotGoodsSet modelWithDictionary:dic];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)homtAdsList
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/wapAdv.do", ServerUrl];
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDHomeAdsSet *set = [DDHomeAdsSet modelWithDictionary:dic];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)hotSearch
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/homepage/hotList.do", ServerUrl];
    
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DDHotSearchSet *set = [DDHotSearchSet modelWithDictionary:dic];
        [subject sendNext:set];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
@end
